package fpeas.tests;

import fpeas.function.Function;
import static fpeas.function.FunctionUtility.constant;
import static fpeas.function.FunctionUtility.equal;
import static fpeas.util.Collections.filter;
import static fpeas.util.Collections.min;

import java.util.ArrayList;
import static java.util.Arrays.asList;
import java.util.List;

public class TestMin
{
	public static boolean testMin1()
	{
		final List<Integer> list=new ArrayList<Integer>();

		list.add(4);
		list.add(2);
		list.add(16);
		
		return min(list).accept(equal(2), false);
	}

	public static boolean testMin2()
	{
		return min(new ArrayList<Integer>()).accept(constant(false), true);
	}

	public static boolean testFilter()
	{
		final Function<Integer, Boolean> isOdd=new Function<Integer,Boolean>()
		{
			public Boolean run(final Integer value)
			{
				return 0!=value%2;
			}
		};

		for (final Integer value: filter(asList(1,2,3,4,5,6),isOdd))
			if (0==value%2)
				return false;
		
		return true;
	}

	public static void main(final String[] args)
	{
		if (!(testMin2() && testMin1() && testFilter()))
			System.exit(1);
	}
}